package offerv1;

//2=1+1
//3=2+1
//4=3+1 4=2+2 4=2+1+1 4=1+1+1+1
//5=4+1 5=3+2
//6=5+1 6=4+2 6=3+3
//7=6+1 7=5+2 7=4+3
//8=8+0 8=7+1 8=6+2 8=5+3 8=4+4
public class Offer14 {
    public static void main(String[] args) {
        Offer14 offer14 = new Offer14();
        System.out.println(offer14.cuttingRope(4));
    }

    public int cuttingRope(int n) {
        if (n < 2) {
            return 1;
        }

        int[] dict = new int[n + 1];
        dict[0] = 0;
        dict[1] = 1;
        for (int i = 2; i <= n; i++) {
            int max = i == n ? 0 : i;
            for (int j = i - 1; j >= i / 2; j--) {
                max = Math.max(max, dict[j] * dict[i - j]);
            }
            dict[i] = max;
        }
        return dict[n];
    }
}
